/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.base.client;

import com.xy.biz.base.domain.req.*;
import com.xy.biz.base.domain.resp.GetGoodsBatchResponse;
import com.xy.lang.domain.Page;
import com.xy.lang.domain.Result;
import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 *
 *
 * @author zgy
 * @date 2021-9-22
 */
public interface GoodsBatchClient {

    /**
     * 查找一个
     *
     * @param request
     * @return
     */
    Result<GetGoodsBatchResponse> getGoodsBatch(GetGoodsBatchRequest request);

    /**
     * 查找多个
     *
     * @param collection 标识集合
     * @return
     */
    Result<List<GetGoodsBatchResponse>> listGoodsBatchById(Collection<Long> collection);

    default Map<Long, GetGoodsBatchResponse> mapGoodsBatchById(Collection<Long> collection) {
        if(CollectionUtils.isEmpty(collection)) {
            return Collections.emptyMap();
        }
        Result<List<GetGoodsBatchResponse>> result = listGoodsBatchById(collection);
        if(result.wasFailure()) {
            return Collections.emptyMap();
        }
        List<GetGoodsBatchResponse> list = result.getData();
        if(CollectionUtils.isEmpty(list)) {
            return Collections.emptyMap();
        }
        return list.stream().collect(Collectors.toMap(GetGoodsBatchResponse::getGoodsBatchId, e -> e));
    }

    /**
     * 根据货品Id获取批次的分组
     *
     */
    Result<Map<Long, List<GetGoodsBatchResponse>>> groupGoodsBatchByGoodsId(Collection<Long> collection);

    /**
     * 根据货品Id获取批次列表
     *
     */
    Result<List<GetGoodsBatchResponse>> listGoodsBatchBySingleGoodsId(GetGoodsRequest request);

    /**
     * 根据货号获取批次的分组
     *
     */
    Result<Map<String, List<GetGoodsBatchResponse>>> groupGoodsBatchByGoodsCode(Collection<String> collection);

    /**
     * 根据货号获取批次列表
     *
     */
    Result<List<GetGoodsBatchResponse>> listGoodsBatchBySingleGoodsCode(ListGoodsByCodeRequest request);

    /**
     * 根据货品（货品Id或货号）和批号的组合来查询
     *
     * @param requestCollection
     * @return
     */
    Result<List<GetGoodsBatchResponse>> listGoodsBatchByGoodsAndBatch(Collection<GetGoodsBatchByGoodsAndBatchRequest> requestCollection);

    /**
     * 查找多个
     *
     * @param request 查找条件
     * @return
     */
    Result<List<GetGoodsBatchResponse>> listGoodsBatch(ListGoodsBatchRequest request);

    /**
     * 分页查找
     *
     * @param request 查找条件
     * @return
     */
    Result<Page<GetGoodsBatchResponse>> pageGoodsBatch(ListGoodsBatchRequest request);

}
